package priv.liaohaolong.fullstacktest.controller.advice;

import jakarta.servlet.ServletException;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

    public static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(ServletException.class)
    public ResponseEntity<?> handleException(@NotNull Exception e) {
        logger.error("Exception: ", e);
        return ResponseEntity.status(500).body(e.getMessage());
    }

}
